package com.hualan.sfzy.controller;

import com.hualan.sfzy.model.entity.FmClassify;
import com.hualan.sfzy.service.FmClassifyService;
import com.hualan.sfzy.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

import static com.hualan.sfzy.constant.CommonConstant.*;

/**
 * FM分类管理控制器
 */
@RestController
@RequestMapping("/fmClassify")
public class FmClassifyController {

    @Autowired
    private FmClassifyService fmClassifyService;

    /**
     * 添加FM分类
     */
    @PostMapping("/add")
    public Result add(@RequestBody FmClassify fmClassify) {
        int result = fmClassifyService.add(fmClassify);
        return result > 0 ? Result.success() : Result.error();
    }

    /**
     * 编辑FM分类
     */
    @PutMapping("/edit")
    public Result edit(@RequestBody FmClassify fmClassify) {
        int result = fmClassifyService.edit(fmClassify);
        return result > 0 ? Result.success() : Result.error();
    }

    /**
     * 删除FM分类
     */
    @DeleteMapping("/remove/{id}")
    public Result remove(@PathVariable Integer id) {
        int result = fmClassifyService.remove(id);
        return result > 0 ? Result.success() : Result.error();
    }

    /**
     * 批量删除FM分类
     */
    @DeleteMapping("/removeBatch")
    public Result removeBatch(@RequestBody Integer[] ids) {
        int result = fmClassifyService.removeBatch(ids);
        return result > 0 ? Result.success() : Result.error();
    }

    /**
     * 查询所有FM分类
     */
    @GetMapping("/find")
    public Result find() {
        List<FmClassify> fmClassifies = fmClassifyService.find();
        return Result.success(fmClassifies);
    }

    /**
     * 分页查询FM分类
     */
    @GetMapping("/findPage")
    public Result findPage(@RequestParam(defaultValue = "1") Integer pageNum,
                          @RequestParam(defaultValue = "10") Integer pageSize,
                          FmClassify fmClassify) {
        Map<String, Object> result = fmClassifyService.findPage(pageNum, pageSize, fmClassify);
        return Result.success(result);
    }

    /**
     * 根据ID查询FM分类
     */
    @GetMapping("/findById/{id}")
    public Result findById(@PathVariable Integer id) {
        FmClassify fmClassify = fmClassifyService.findById(id);
        return Result.success(fmClassify);
    }
} 